import { MsgSendOrReceiveEnum } from '/@/components/im'
import { formatToDate, formatToDateTime } from '/@/utils/date'

/**
 * 格式化日期（今天显示时分，非今天显示月日）
 * @param date 要格式化的日期
 * @returns
 */
export const formatDate = (date: string) => {
  const targetDate = formatToDate(date, 'MM-DD'),
    targetTime = formatToDateTime(date, 'HH:mm')
  const nowDate = formatToDate(new Date())

  if (targetDate === nowDate) return targetTime
  return targetDate
}

/**
 * 获取消息收发类型
 * @param senderId 发送者id
 * @param myId 我的id
 * @returns
 */
export const getMsgSendOrReceiveType = (senderId: string, myId: string) => (isMsgSend(senderId, myId) ? MsgSendOrReceiveEnum.SEND : MsgSendOrReceiveEnum.REVCEIVE)

/**
 * 是否为发送消息
 * @param senderId 发送者id
 * @param myId 我的id
 */
export const isMsgSend = (senderId: string, myId: string) => senderId === myId

/**
 * 是否为接收消息
 * @param receiveId 接收者id
 * @param myId 我的id
 */
export const isMsgReceive = (receiveId: string, myId: string) => receiveId === myId
